package com.bonc.rms.controller.tms;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.bonc.odk.logmanager.LogManager;
import com.bonc.rms.service.impl.tms.EmployeeServiceimpl;

@Controller
@RequestMapping(value = "/employeeController")
public class EmployeeController {
	@Autowired
	EmployeeServiceimpl employeeService;

	/**
	 * 工龄分布
	 * 
	 * @param departmentId
	 *            按部门查询
	 * @param
	 * @return
	 */
	@RequestMapping(value = "/workAgeDistribute")
	@ResponseBody
	public String getWorkAgeDistribute(Integer departmentId) {
		LogManager.Method("Int Service : EmployeeController -> getWorkAgeDistribute");
		Map<String, Object> workAgeMap = new HashMap<String, Object>();

		workAgeMap.put("title", "工龄分布");

		List<Map<String, String>> workAgeList = new ArrayList<>();

		Map<String, String> workMap = new HashMap<>();
		workMap = employeeService.getWorkAgeDistribute(departmentId);
		for (Map.Entry<String, String> entry : workMap.entrySet()) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("name", entry.getKey());
			map.put("value", entry.getValue());
			workAgeList.add(map);
		}

		workAgeMap.put("headcount", workAgeList);


		LogManager.Method("Out Service : EmployeeController -> getWorkAgeDistribute");
		return JSON.toJSONString(workAgeMap);
	}

	/**
	 * 年龄分布
	 * 
	 * @param departmentId
	 *            按部门查询
	 * @param
	 * @return
	 */

	@RequestMapping(value = "/ageDistribute")
	@ResponseBody
	public String getAgeDistribute(Integer departmentId) {
		LogManager.Method("Int Service : EmployeeController -> getAgeDistribute");
		Map<String, Object> ageMap = new HashMap<String, Object>();
		ageMap.put("title", "年龄分布");

		List<Map<String, String>> ageList = new ArrayList<>();
		Map<String, String> map = new HashMap<>();
		map = employeeService.getAgeDistribute(departmentId);
		for (Map.Entry<String, String> entry : map.entrySet()) {
			Map<String, String> map2 = new HashMap<String, String>();
			map2.put("name", entry.getKey());
			map2.put("value", entry.getValue());
			ageList.add(map2);
		}

		ageMap.put("headcount", ageList);


		LogManager.Method("Out Service : EmployeeController -> getAgeDistribute");
		return JSON.toJSONString(ageMap);
	}

}
